package org.tong.web;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.tong.aspect.AspectCfg;
import org.tong.jackson.JsonUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author
 * @date 2022-08-25 15:23
 */
@Controller
@RequestMapping("/web")
@Slf4j
public class WebController {

    @GetMapping("/index")
    @AspectCfg.VistLog
    public String toIndex(HttpServletRequest request) {
        log.info("request={}", JsonUtil.toJson(request.getParameterMap()));
        return "index.html";
    }

    @GetMapping("/redirect")
    public String toRedirect(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        log.info("request={}", JsonUtil.toJson(request.getParameterMap()));
        //RequestDispatcher requestDispatcher = request.getRequestDispatcher("/web/index");
        ///requestDispatcher.forward(request, response);
        //return "forward:/web/index";
//        Cookie cookie = new Cookie("abc","as");
//        cookie.setDomain("baidu.com");
//        response.addCookie(cookie);

        return "redirect:/web/index";
    }
}
